home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / mac / files / t_sys5 / bm_cpio.gz / unixbm.cpio / bmutil.c < prev    next >
C/C++ Source or Header  |  1994-07-11  |  16KB  |  781 lines

  1. /* bmutil.c */
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #include <time.h>
  6.  
  7. #define        SETVBUF
  8. #if    defined(UNIX) || defined(MICROSOFT)
  9. #include    <sys/types.h>
  10. #endif
  11. #if    defined(UNIX) || defined(MICROSOFT) || defined(__TURBOC__)
  12. #include    <sys/stat.h>
  13. #endif
  14. #ifdef AZTEC
  15. #include <stat.h>
  16. #endif
  17. #include <fcntl.h>
  18. #include "bm.h"
  19. #include "header.h"
  20.  
  21. char *getname();
  22. static unsigned long    mboxsize;
  23. static int    anyread;
  24.  
  25. #ifdef SETVBUF
  26. #define        MYBUF    4096
  27. char    *inbuf = NULLCHAR;    /* the stdio buffer for the mail file */
  28. char    *outbuf = NULLCHAR;    /* the stdio file io buffer for the temp file */
  29. #endif
  30.  
  31. int
  32. initnotes()
  33. {
  34.     FILE    *tmpfile();
  35.     FILE    *ifile;
  36.     register struct    let *cmsg;
  37.     int     i, ret;
  38.     struct stat mstat;
  39.  
  40.     if (!stat(mfilename,&mstat))
  41.         mboxsize = mstat.st_size;
  42.     if ((ifile = fopen(mfilename,"r")) == NULLFILE) {
  43.         printf(nomail);
  44.         mfile = NULLFILE;
  45.         return 0;
  46.     } 
  47. #ifdef    SETVBUF
  48.     if (inbuf == NULLCHAR)
  49.         inbuf = malloc(MYBUF);
  50.     setvbuf(ifile, inbuf, _IOFBF, MYBUF);
  51. #endif
  52.     if ((mfile = tmpfile()) == NULLFILE) {
  53.         printf("Unable to create tmp file\n");
  54.         (void) fclose(ifile);
  55.         return -1;
  56.     }
  57. #ifdef SETVBUF
  58.     if (outbuf == NULLCHAR)
  59.         outbuf = malloc(MYBUF);
  60.     setvbuf(mfile, outbuf, _IOFBF, MYBUF);
  61. #endif
  62.     nmsgs = 0;
  63.     current = 0;
  64.     change = 0;
  65.     newmsgs = 0;
  66.     anyread = 0;
  67.     ret = readnotes(ifile);
  68.     (void) fclose(ifile);
  69.     if (ret != 0)
  70.         return -1;
  71. #ifdef SETVBUF
  72.     if (inbuf != NULLCHAR) {
  73.         (void) free(inbuf);
  74.         inbuf = NULLCHAR;
  75.     }
  76. #endif
  77.     for (cmsg = &mbox[1],i = 1; i <= nmsgs; i++, cmsg++)  
  78.         if ((cmsg->status & READ) == 0) {
  79.             newmsgs++;
  80.             if (current == 0)
  81.                 current = i;
  82.         }
  83.     /* start at one if no new messages */
  84.     if (current == 0)
  85.         current++;
  86.  
  87.     return 0;
  88.  
  89. }
  90.  
  91. /* readnotes assumes that ifile is pointing to the first
  92.  * message that needs to be read.  For initial reads of a
  93.  * notesfile, this will be the beginning of the file.  For
  94.  * rereads when new mail arrives, it will be the first new
  95.  * message.
  96.  */
  97. readnotes(ifile)
  98. FILE *ifile ;
  99. {
  100.     char     tstring[LINELEN];
  101.     long    cpos;
  102.     register struct    let *cmsg;
  103.     register char *line;
  104.     long    ftell();
  105.  
  106.     cmsg = (struct let *)NULL;
  107.     line = tstring;
  108.     while(!feof(ifile)) {
  109.         fgets(line,LINELEN,ifile);
  110.         /* scan for begining of a message */
  111.         if(strncmp(line,"From ",5) == 0) {
  112.             cpos = ftell(mfile);
  113.             fputs(line,mfile);
  114.             if (nmsgs == maxlet) {
  115.                 printf("Mail box full: > %d messages\n",maxlet);
  116.                 (void) fclose(mfile);
  117.                 return -1;
  118.             }
  119.             nmsgs++;
  120.             cmsg = &mbox[nmsgs];
  121.             cmsg->start = cpos;
  122.             cmsg->status = 0;
  123.             cmsg->size = strlen(line);
  124.             while (!feof(ifile)) {
  125.                 if (fgets(line,LINELEN,ifile) == NULLCHAR)
  126.                     break;
  127.                 if (*line == '\n') { /* done header part */
  128.                     cmsg->size++;
  129.                     putc(*line, mfile);
  130.                     break;
  131.                 }
  132.                 if (htype(line) == STATUS) {
  133.                     if (line[8] == 'R') 
  134.                         cmsg->status |= READ;
  135.                     continue;
  136.                 }
  137.                 cmsg->size += strlen(line);
  138.                 if (fputs(line,mfile) == EOF) {
  139.                     perror("tmp file");
  140.                     (void) fclose(mfile);
  141.                     return -1;
  142.                 }
  143.  
  144.             }
  145.         } else if (cmsg) {
  146.             cmsg->size += strlen(line);
  147.             fputs(line,mfile);
  148.         }
  149.     }
  150.     return 0;
  151. }
  152.  
  153. /* list headers of a notesfile a message */
  154. listnotes()
  155. {
  156.     register struct    let *cmsg;
  157.     register char    *p, *s;
  158.     char    smtp_date[SLINELEN];
  159.     char    smtp_from[SLINELEN];
  160.     char    smtp_subject[SLINELEN]; 
  161.     char    tstring[LINELEN];
  162.     int    i,c;
  163.     int    lines;
  164.     long    size;
  165.  
  166.     if (mfile == NULLFILE)
  167.         return;
  168.  
  169.     screen_clear();
  170.     setrawmode();
  171.     printf("Mailbox %s - %d messages %d new\n\n",mfilename,nmsgs,newmsgs);
  172.     lines = 2;
  173.     for (cmsg = &mbox[1],i = 1; i <= nmsgs; i++, cmsg++) {
  174.         *smtp_date = '\0';
  175.         *smtp_from = '\0';
  176.         *smtp_subject = '\0';
  177.         fseek(mfile,cmsg->start,0);
  178.         size = cmsg->size;
  179.         while (!feof(mfile) && size > 0) {
  180.             fgets(tstring,sizeof(tstring),mfile);
  181.             if (*tstring == '\n')    /* end of header */
  182.                 break;
  183.             size -= strlen(tstring);
  184.             rip(tstring);
  185.             /* handle continuation later */
  186.             if (*tstring == ' '|| *tstring == '\t')
  187.                 continue;
  188.             switch(htype(tstring)) {
  189.             case FROM:
  190.                 if((p = getname(tstring)) == NULLCHAR) {
  191.                     p = &tstring[6];
  192.                     while(*p && *p != ' ' && *p != '(')
  193.                         p++;
  194.                     *p = '\0';
  195.                     p = &tstring[6];
  196.                 }
  197.                 sprintf(smtp_from,"%.30s",p);
  198.                 break;
  199.             case SUBJECT:
  200.                 sprintf(smtp_subject,"%.34s",&tstring[9]);
  201.                 break;
  202.             case DATE:
  203.                 if ((p = strchr(tstring,',')) == NULLCHAR)
  204.                     p = &tstring[6];
  205.                 else
  206.                     p++;
  207.                 /* skip spaces */
  208.                 while (*p == ' ') p++;
  209.                 if(strlen(p) < 17)
  210.                     break;     /* not a valid length */
  211.                 s = smtp_date;
  212.                 /* copy day */
  213.                 if (atoi(p) < 10 && *p != '0') {
  214.                     *s++ = ' ';
  215.                 } else
  216.                     *s++ = *p++;
  217.                 *s++ = *p++;
  218.  
  219.                 *s++ = ' ';
  220.                 while (*p == ' ')
  221.                     p++;
  222.                 /* copy month */
  223.                 *s++ = *p++;
  224.                 *s++ = *p++;
  225.                 *s++ = *p++;
  226.                 while (*p == ' ')
  227.                     p++;
  228.                 /* skip year */
  229.                 while (isdigit(*p))
  230.                     p++;
  231.                 /* copy time */
  232.                 *s++ = *p++;    /* space */
  233.                 *s++ = *p++;    /* hour */
  234.                 *s++ = *p++;
  235.                 *s++ = *p++;    /* : */
  236.                 *s++ = *p++;    /* min */
  237.                 *s++ = *p++;
  238.                 *s = '\0';
  239.                 break;
  240.             case NOHEADER:
  241.                 break;
  242.             }
  243.         }
  244.         printf("%c%c%c%3d %-27.27s %-12.12s %5ld %.25s\n",
  245.             (i == current ? '>' : ' '),
  246.             (cmsg->status & DELETE ? 'D' : ' '),
  247.             (cmsg->status & READ ? 'Y' : 'N'),
  248.             i, smtp_from, smtp_date,
  249.             cmsg->size, smtp_subject);
  250.         if ((++lines % (MAXROWS - 1)) == 0) {
  251.             printf("- more -");
  252.             c = getrch();
  253.             printf("\r         \r");
  254.             if( c == EOF || c == 'q')
  255.                 break;
  256.             screen_clear();
  257.             lines = 0;
  258.         }
  259.     }
  260.     setcookedmode();
  261. }
  262.  
  263. /*  save msg on stream - if noheader set don't output the header */
  264. int
  265. msgtofile(msg,tfile,noheader)
  266. int msg;
  267. FILE *tfile;   /* already open for write */
  268. int noheader;
  269. {
  270.     char    tstring[LINELEN];
  271.     long     size;
  272.  
  273.     if (mfile == NULLFILE) {
  274.         printf(nomail);
  275.         return -1;
  276.     }
  277.     fseek(mfile,mbox[msg].start,0);
  278.     size = mbox[msg].size;
  279.     if ((mbox[msg].status & READ) == 0) {
  280.         mbox[msg].status |= READ;
  281.         change = 1;
  282.     }
  283.  
  284.     if (noheader) {
  285.         /* skip header */
  286.         while (!feof(mfile) && size > 0) {
  287.             fgets(tstring,sizeof(tstring),mfile);
  288.             size -= strlen(tstring);
  289.             if (*tstring == '\n')
  290.                 break;
  291.         }
  292.     }
  293.     while (!feof(mfile) && size > 0) {
  294.         fgets(tstring,sizeof(tstring),mfile);
  295.         size -= strlen(tstring);
  296.         fputs(tstring,tfile);
  297.         if (ferror(tfile)) {
  298.             printf("Error writing mail file\n");
  299.             (void) fclose(tfile);
  300.             return -1;
  301.         }
  302.     }
  303.     return 0;
  304. }
  305.  
  306. /*  delmsg - delete message in current notesfile */
  307. delmsg(msg)
  308. int msg;
  309. {
  310.     if (mfile == NULLFILE) {
  311.         printf(nomail);
  312.         return;
  313.     }
  314.     mbox[msg].status |= DELETE;
  315.     change = 1;
  316. }
  317.  
  318. /*  reply - to a message  */
  319. reply(msg)
  320. int msg;
  321. {
  322.     char     to[SLINELEN];
  323.     char    subject[LINELEN];
  324.     char    tstring[LINELEN];
  325.     char     *p,*s;
  326.     char    *toarg[1];
  327.     long    size;
  328.  
  329.     if (mfile == NULLFILE) {
  330.         printf(nomail);
  331.         return;
  332.     }
  333.     *to = '\0';
  334.     *subject = '\0';
  335.     fseek(mfile,mbox[msg].start,0);
  336.     size = mbox[msg].size;
  337.     while (!feof(mfile) && size > 0) {
  338.         fgets(tstring,sizeof(tstring),mfile);
  339.         size -= strlen(tstring);
  340.         if (*tstring == '\n')     /* end of header */
  341.             break;
  342.         rip(tstring);
  343.         if ((*to == '\0' && htype(tstring) == FROM)
  344.             || htype(tstring) == REPLYTO) {
  345.             s = getname(tstring);
  346.             if (s == NULLCHAR) {
  347.                 p = strchr(tstring,':');
  348.                 p += 2;
  349.                 s = p;
  350.                 while(*p && *p != ' ' && *p != '(')
  351.                     p++;
  352.                 *p = '\0';
  353.             }
  354.             *to = '\0';
  355.             strncat(to,s,sizeof(to));
  356.         } else if (htype(tstring) == SUBJECT) {
  357.             if (strncmp(&tstring[9], "Re:", 3))  /* No Re: yet? */
  358.                 sprintf(subject,"Re: %s\n",&tstring[9]);
  359.             else    /* there's an Re:, let's not add another */
  360.                 sprintf(subject,"%s\n",&tstring[9]) ;
  361.         }
  362.     }
  363.     if (*to == '\0')
  364.         printf("No reply address in message\n");
  365.     else {
  366.         toarg[0] = to;
  367.         dosmtpsend(NULLFILE,toarg,1,subject);
  368.     }
  369. }
  370.  
  371.  
  372. /* close the temp file while coping mail back to the mailbox */
  373. int
  374. closenotes()
  375. {
  376.     register struct    let *cmsg;
  377.     register char *line;
  378.     char tstring[LINELEN];
  379.     long size;
  380.     int i;
  381.     int ret;
  382.     FILE    *nfile;
  383.     struct stat mstat;
  384.  
  385.     if (mfile == NULLFILE)
  386.         return 0;
  387.     if (!change) {
  388.         (void) fclose(mfile);
  389.         return 0;
  390.     }
  391.     line = tstring;
  392.     fseek(mfile,0L,2);
  393.     if (isnewmail()) {
  394.         if ((nfile = fopen(mfilename,"r")) == NULLFILE)
  395.             perror(mfilename);
  396.         else {
  397.             /* seek to end of old msgs */
  398.             fseek(nfile,mboxsize,0);
  399.             /* seek to end of tempfile */
  400.             fseek(mfile,0L,2);
  401.             ret = readnotes(nfile);   /* get the new mail */
  402.             (void) fclose(nfile);
  403.             if (ret != 0) {
  404.                 printf("Error updating mail file\n");
  405.                 return -1;
  406.             }
  407.         }
  408.     }
  409.  
  410.     if ((nfile = fopen(mfilename,"w")) == NULLFILE) {
  411.         printf("Unable to open %s\n",mfilename);
  412.         return -1;
  413.     }
  414.     /* copy tmp file back to notes file */
  415.     for (cmsg = &mbox[1],i = 1; i <= nmsgs; i++, cmsg++) {
  416.         fseek(mfile,cmsg->start,0);
  417.         size = cmsg->size;
  418.         if ((cmsg->status & DELETE))
  419.             continue;
  420.         /* copy the header */
  421.         while (!feof(mfile) && size > 0) {
  422.             fgets(line,LINELEN,mfile);
  423.             size -= strlen(line);
  424.             if (*line == '\n') {
  425.                 if ((cmsg->status & READ) != 0)
  426.                     fprintf(nfile,"Status: R\n");
  427.                 fprintf(nfile,"\n");
  428.                 break;
  429.             }
  430.             fputs(line,nfile);
  431.         }
  432.         while (!feof(mfile) && size > 0) {
  433.             fgets(line,LINELEN,mfile);
  434.             fputs(line,nfile);
  435.             size -= strlen(line);
  436.             if (ferror(nfile)) {
  437.                 printf("Error writing mail file\n");
  438.                 (void) fclose(nfile);
  439.                 (void) fclose(mfile);
  440.                 return -1;
  441.             }
  442.         }
  443.     }
  444.     nmsgs = 0;
  445.     (void) fclose(nfile);
  446.     (void) fclose(mfile);
  447.     mfile = NULLFILE;
  448.  
  449.     /* remove a zero length file */
  450.     if (stat(mfilename,&mstat) == 0  && mstat.st_size == 0)
  451.         (void) unlink(mfilename);
  452.     return 0;
  453. }
  454.  
  455. /* get a message id from the sequence file */
  456. long 
  457. get_msgid()
  458. {
  459.     char sfilename[SLINELEN];
  460.     char s[20];
  461.     long sequence = 0L;
  462.     FILE *sfile;
  463.     long atol();
  464.  
  465.     sprintf(sfilename,"%s/sequence.seq", mqueue);
  466.     sfile = fopen(sfilename,"r");
  467.  
  468.     /* if sequence file exists, get the value, otherwise set it */
  469.     if (sfile != NULLFILE) {
  470.         fgets(s,sizeof(s),sfile);
  471.         sequence = atol(s);
  472.     /* Keep it in range of and 8 digit number to use for dos name prefix. */
  473.         if (sequence < 0L || sequence > 99999999L )
  474.             sequence = 0L;
  475.         (void) fclose(sfile);
  476.     }
  477.  
  478.     /* increment sequence number, and write to sequence file */
  479.     sfile = fopen(sfilename,"w");
  480.     fprintf(sfile,"%ld",++sequence);
  481.     (void) fclose(sfile);
  482.     return sequence;
  483. }
  484.  
  485. /* Given a string of the form <user@host>, extract the part inside the
  486.  * brackets and return a pointer to it.
  487.  */
  488. char *
  489. getname(cp)
  490. register char *cp;
  491. {
  492.     char *cp1;
  493.  
  494.     if((cp = strchr(cp,'<')) == NULLCHAR)
  495.         return NULLCHAR;
  496.     cp++;    /* cp -> first char of name */
  497.     if((cp1 = strchr(cp,'>')) == NULLCHAR)
  498.         return NULLCHAR;
  499.     *cp1 = '\0';
  500.     return cp;
  501. }
  502.  
  503. /* create mail lockfile */
  504. int
  505. mlock(dir,id)
  506. char *dir;
  507. char *id;
  508. {
  509.     char lockname[SLINELEN];
  510.     int fd;
  511.     /* Try to create the lock file in an atomic operation */
  512.     sprintf(lockname,"%s/%.8s.lck",dir,id);
  513.     if((fd = open(lockname, O_WRONLY|O_EXCL|O_CREAT,0600)) == -1)
  514.         return -1;
  515.     (void) close(fd);
  516.     return 0;
  517. }
  518.  
  519. /* remove mail lockfile */
  520. int
  521. rmlock(dir,id)
  522. char *dir;
  523. char *id;
  524. {
  525.     char lockname[SLINELEN];
  526.     sprintf(lockname,"%s/%.8s.lck",dir,id);
  527.     (void) unlink(lockname);
  528. }
  529.  
  530. /* parse a line into argv array. Return argc */
  531. int
  532. parse(line,argv,maxargs)
  533. register char *line;
  534. char *argv[];
  535. int maxargs;
  536. {
  537.     int argc;
  538.     int qflag;
  539.     register char *cp;
  540.  
  541.     for(argc = 0; argc < maxargs; argc++)
  542.         argv[argc] = NULLCHAR;
  543.  
  544.     for(argc = 0; argc < maxargs;){
  545.         qflag = 0;
  546.         /* Skip leading white space */
  547.         while(*line == ' ' || *line == '\t')
  548.             line++;
  549.         if(*line == '\0')
  550.             break;
  551.         /* Check for quoted token */
  552.         if(*line == '"'){
  553.             line++;    /* Suppress quote */
  554.             qflag = 1;
  555.         }
  556.         argv[argc++] = line;    /* Beginning of token */
  557.         /* Find terminating delimiter */
  558.         if(qflag){
  559.             /* Find quote, it must be present */
  560.             if((line = strchr(line,'"')) == NULLCHAR){
  561.                 return -1;
  562.             }
  563.             *line++ = '\0';
  564.         } else {
  565.             /* Find space or tab. If not present,
  566.              * then we've already found the last
  567.              * token.
  568.              */
  569.             if((cp = strchr(line,' ')) == NULLCHAR
  570.                 && (cp = strchr(line,'\t')) == NULLCHAR){
  571.                 break;
  572.             }
  573.             *cp++ = '\0';
  574.             line = cp;
  575.         }
  576.     }
  577.     return argc;
  578. }
  579.  
  580. lockit()
  581. {
  582.     char line[SLINELEN];
  583.     while(mlock(maildir,notename)) {
  584.         printf("Mail file is busy, Abort or Retry ? ");
  585.         gets(line);
  586.         if (*line == 'A' || *line == 'a') {
  587.             if ( mfile != NULLFILE)
  588.                 (void) fclose(mfile);
  589.             mfile = NULLFILE;
  590.             return 1;
  591.         }
  592.     }
  593.     return 0;
  594. }
  595.  
  596. /* print the next message or the current on of new */
  597. printnext()
  598. {
  599.     if (mfile == NULLFILE)
  600.         return;
  601.     if ((mbox[current].status & READ) != 0) {
  602.         if (current == 1 && anyread == 0)
  603.             ;
  604.         else if (current < nmsgs) {
  605.             current++;
  606.         } else {
  607.             printf("Last message\n");
  608.             return;
  609.         }
  610.     }
  611.     displaymsg(current);
  612.     anyread = 1;
  613. }
  614.  
  615. /*  display message on the crt given msg number */
  616. displaymsg(msg)
  617. int msg;
  618. {
  619.     register int c;
  620.     register int col;
  621.     char    buf[MAXCOL+2];        /* line buffer */
  622.     int    lines;
  623.     int    cnt;
  624.     long     tsize, size;
  625.  
  626.     if (mfile == NULLFILE) {
  627.         printf(nomail);
  628.         return;
  629.     }
  630.     if( msg < 0 || msg > nmsgs) {
  631.         printf(badmsg,msg);
  632.         return;
  633.     }
  634.     setrawmode();
  635.     screen_clear();
  636.     fseek(mfile,mbox[msg].start,0);
  637.     size = mbox[msg].size;
  638.     tsize = size;
  639.  
  640.     printf("Message #%d %s\n",
  641.         msg, mbox[msg].status & DELETE ? "[Deleted]" : "");
  642.     if ((mbox[msg].status & READ) == 0) {
  643.         mbox[msg].status |= READ;
  644.         change = 1;
  645.     }
  646.     lines = 1;
  647.     col = 0;
  648.     while (!feof(mfile) && size > 0) {
  649.         for (col = 0;  col < MAXCOL-2;) {
  650.             c = getc(mfile);
  651.             size--;
  652.             if (feof(mfile) || size == 0)    /* end this line */
  653.                 break;
  654.             if (c == '\t') {
  655.                 cnt = col + 8 - (col & 7);
  656.                 if (cnt >= MAXCOL)    /* end this line */
  657.                     break;
  658.                 while (col < cnt)
  659.                     buf[col++] = ' ';
  660.             } else if (c == '\n')
  661.                 break;
  662.             else
  663.                 buf[col++] = c;
  664.         }
  665. #ifdef __TURBOC__
  666.         buf[col++] = '\r';
  667.         buf[col++] = '\n';
  668.         buf[col] = '\0';
  669.         cputs(buf);
  670. #else
  671.         buf[col] = '\0';
  672.         puts(buf);
  673. #endif
  674.         col = 0;
  675.         if ((++lines == (MAXROWS-1))) {
  676.             printf("- more -(%d%%)",(tsize-size)*100/tsize);
  677.             c = getrch();
  678.             printf("\r               \r");
  679.             if( c == EOF || c == 'q')
  680.                 break;
  681.             screen_clear();
  682.             lines = 0;
  683.         }
  684.     }
  685.     setcookedmode();
  686. }
  687.  
  688. /* list jobs wating to be sent in the mqueue */
  689. listqueue()
  690. {
  691.     char tstring[80];
  692.     char workfile[80];
  693.     char line[20];
  694.     char host[SLINELEN];
  695.     char to[SLINELEN];
  696.     char from[SLINELEN];
  697.     char *p;
  698.     char    status;
  699.     struct stat stbuf;
  700.     struct tm *tminfo, *localtime();
  701.     FILE *fp;
  702.  
  703.     printf("S     Job    Size Date  Time  Host                 From\n");
  704.     sprintf(workfile,"%s/%s",mqueue,WORK);
  705.     filedir(workfile,0,line);
  706.     while(line[0] != '\0') {
  707.         sprintf(tstring,"%s/%s",mqueue,line);
  708.         if ((fp = fopen(tstring,"r")) == NULLFILE) {
  709.             perror(tstring);
  710.             continue;
  711.         }
  712.         if ((p = strrchr(line,'.')) != NULLCHAR)
  713.             *p = '\0';
  714.         sprintf(tstring,"%s/%s.lck",mqueue,line);
  715.         if (access(tstring,0))
  716.             status = ' ';
  717.         else
  718.             status = 'L';
  719.         sprintf(tstring,"%s/%s.txt",mqueue,line);
  720.         stat(tstring,&stbuf);
  721.         tminfo = localtime(&stbuf.st_ctime);
  722.         fgets(host,sizeof(host),fp);
  723.         rip(host);
  724.         fgets(from,sizeof(from),fp);
  725.         rip(from);
  726.         printf("%c %7s %7ld %02d/%02d %02d:%02d %-20s %s\n      ",
  727.             status, line, stbuf.st_size,
  728.             tminfo ->tm_mon+1,
  729.             tminfo->tm_mday,
  730.             tminfo->tm_hour,
  731.             tminfo->tm_min,
  732.             host,from);
  733.         while (fgets(to,sizeof(to),fp) != NULLCHAR) {
  734.             rip(to);
  735.             printf("%s ",to);
  736.         }
  737.         printf("\n");
  738.         (void) fclose(fp);
  739.         filedir(workfile,1,line);
  740.     }
  741. }
  742.  
  743. /* kill a job in the mqueue */
  744. killjob(j)
  745. char *j;
  746. {
  747.     char s[SLINELEN];
  748.     char tbuf[SLINELEN];
  749.     char *p;
  750.     sprintf(s,"%s/%s.lck",mqueue,j);
  751.     p = strrchr(s,'.');
  752.     if (!access(s,0)) {
  753.         printf("Warning Job %s is locked by SMTP. Remove (y/n)? ",j);
  754.         gets(tbuf);
  755.         if (*tbuf != 'y')
  756.             return;
  757.         (void) unlink(s);
  758.     }
  759.     strcpy(p,".wrk");
  760.     if (unlink(s))
  761.         printf("Job id %s not found\n",j);
  762.     strcpy(p,".txt");
  763.     (void) unlink(s);
  764. }
  765.  
  766. /* check the current mailbox to see if new mail has arrived.
  767. * checks to see if the file has increased in size.
  768. * returns true if new mail has arrived.
  769. */
  770. isnewmail()
  771. {
  772.     struct stat mstat;
  773.     if (mfile == NULLFILE)
  774.         return 0;
  775.     if (stat(mfilename,&mstat))
  776.         printf("unable to stat %s\n",mfilename);
  777.     else if (mstat.st_size > mboxsize)
  778.             return 1;
  779.     return 0;
  780. }
  781.